using System;
using System.Windows.Forms;
using System.Drawing;

public class DGVCalendarColumn : DataGridViewColumn, IDGVColumn
{
    public DGVCalendarColumn()
        : base(new DGVCalendarCell())
    {
        this.SortMode = DataGridViewColumnSortMode.Automatic;
    }

    public override DataGridViewCell CellTemplate
    {
        get { return base.CellTemplate; }
        set
        {
            // Ensure that the cell used for the template is a DGVCalendarCell.
            if (value != null && !value.GetType().IsAssignableFrom(typeof(DGVCalendarCell)))
            {
                throw new InvalidCastException("Must be a DGVCalendarCell");
            }
            base.CellTemplate = value;
        }
    }

    // IDGVColumn.EditingLabel()
    public Label EditingLabel()
    {
        return new DBLabel(this.HeaderText);
    }

    // IDGVColumn.EditingControl
    public Control EditingControl()
    {
        DateTimePicker _dtp = new DateTimePicker();
        _dtp.Format = DateTimePickerFormat.Short;
        _dtp.DataBindings.Add(new Binding("Text", this.DataGridView.DataSource, this.DataPropertyName, true));
        return _dtp;
    }
}
